package com.niji.littly_donkey_android.util;

import android.app.Activity;

import android.widget.ImageView;

import com.niji.littly_donkey_android.R;
import com.niji.littly_donkey_android.http.NetworkImageLoader;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;

 
/**
 * 用Glide实现网络图片加载器
 */
public class NetworkGlideImageLoader implements NetworkImageLoader {
 
    private static NetworkGlideImageLoader mInstance;
    private NetworkGlideImageLoader(){
 
    }
 
    public static NetworkGlideImageLoader getInstance(){
        if(mInstance == null){
            synchronized(NetworkGlideImageLoader.class){
                if(mInstance == null)
                    mInstance = new NetworkGlideImageLoader();
            }
        }
        return mInstance;
    }
 
    @Override
    public void displayImage(Activity activity, String path, ImageView imageView, int width, int height) {

 
        Glide.with(activity)                             //配置上下文
//                .load(Uri.fromFile(new File("/storage/emulated/0/DCIM/Video/VID_20200313_084219.mp4")))      //设置图片路径(fix #8,文件名包含%符号 无法识别和显示) 本地路径
                    .load(path)                               //网络图片路径
//                    .listener(new RequestListener<String, GlideDrawable>() {
//                        @Override
//                        public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
//                            Logs.i("网络图片加载异常");
//                            return false;
//                        }
//
//                        @Override
//                        public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
//                            return false;
//                        }
//                    })
                    .error(R.mipmap.bj)           //设置错误图片
                    .placeholder(R.mipmap.bj)     //设置占位图片
                    .diskCacheStrategy(DiskCacheStrategy.ALL)//缓存全尺寸
//                    .diskCacheStrategy(DiskCacheStrategy.RESULT)
                    .into(imageView);
    }
 
 
   
 
}
